//
//  BN_ParentMeansViewController.m
//  BabyNow
//
//  Created by 刘泽琛 on 14-5-30.
//  Copyright (c) 2014年 iMobile. All rights reserved.
//

#import "BN_ParentMeansViewController.h"

@interface BN_ParentMeansViewController () {
    BN_Mine_diffParentData *parentData_;
    MJRefreshHeaderView *_header;
    UIButton *backButton_;
}

@end

@implementation BN_ParentMeansViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    // 自动校正嵌入的ScrollView
    if (IOS7) {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // ui
    // 列表
    _mineTaleView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, FULLSCREEN_HEIGHT)];
    [self setExtraCellLineHidden:_mineTaleView];
    [self.view addSubview:_mineTaleView];
    
    // 按钮
    backButton_ = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton_.frame = CGRectMake(9, 20, 44, 44);
    [backButton_ setImage:[UIImage imageNamed:@"quxiao"] forState:UIControlStateNormal];
    [backButton_ addTarget:self action:@selector(backVc) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backButton_];
    
    // data
    [self initData];
}

- (void)initData {
    if (!parentData_) {
        parentData_ = [[BN_Mine_diffParentData alloc]init];
    }
    _mineTaleView.delegate = parentData_;
    _mineTaleView.dataSource = parentData_;
    [parentData_ toReloadParentList:^(BOOL isReload) {
        if (isReload) {
            [_mineTaleView reloadData];
        }
    }];
    [parentData_ preload];
    
    MJRefreshHeaderView *header = [MJRefreshHeaderView header];
    header.scrollView = _mineTaleView;
    header.delegate = parentData_;
    _header = header;
}

- (void)backVc {
    [self releaseResource];
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)releaseResource {
    [_header free];
    _header.delegate = nil;
    _header = nil;
    
    _mineTaleView.delegate = nil;
    _mineTaleView.dataSource = nil;
    _mineTaleView = nil;
    
    parentData_.mineParentListRelad = nil;
    parentData_ = nil;
}

- (void)dealloc
{
    [self releaseResource];
    NSLog(@"家长角色首页 释放...");
}
@end
